package com.qfjy.homework.student.yg.prox.util;

import com.qfjy.homework.student.yg.prox.handler.TransactionHandler;
import com.qfjy.homework.student.yg.prox.transaction.DaoTransaction;

import java.lang.reflect.Proxy;

public class ProxyUtil {
    public static Object createProxy(Object object){
        //增强类对象
        DaoTransaction daoTransaction = new DaoTransaction();
        //方法拦截处理器
        TransactionHandler handler = new TransactionHandler(daoTransaction,object);

        //获取代理类实例对象
        Object proxy = Proxy.newProxyInstance(object.getClass().getClassLoader(),
                object.getClass().getInterfaces(), handler);

        return proxy;
    }
}
